import { ref, computed } from 'vue'
import { defineStore } from 'pinia'
import { getLoginUserUsingGet, loginUsingPost } from '@/api/yonghujiekou.ts'
import { message } from 'ant-design-vue'

/**
 * 存储登录用户信息的状态
 */
export const useLoginUserStore = defineStore('loginUser', () => {

  const loginUser = ref<API.UserVo>({
    userName: "未登录"
  })

  /**
   * 获取登录用户信息
   */
  async function fetchLoginUser() {

      const res = await getLoginUserUsingGet()
      if (res.data.code === 0 && res.data.data) {
        loginUser.value = res.data.data
      }
  }


  /**
   * 设置登录用户信息
   * @param newLoginUser
   */
  function setLoginUser(newLoginUser: any) {
    loginUser.value = newLoginUser;
  }



  return { loginUser, fetchLoginUser, setLoginUser }
})
